//剑指offer66 机器人的运动 
思路：dfs算法--深度优先算法
public class Solution{
	public int movingCount(int threshold,int rows,int cols){
		if(rows<=0||cols<=0||threshold<0){
			return 0;
		}
		boolean[][] isVisited=new boolean[rows][cols];//标记这条路是否走过
		return movingCountCore(threshold,rows,cols,0,0,isVisited);//从0,0开始走
	}
	public int movingCountCore(int threshold,int rows,int cols,int row,int col,boolean isVisited){
		if(rows<0||cols<0||isVisited||row>rows||col>cols||cal(col)+cal(row)>threshold){
			return 0;
		}
		isVisited[row][col]=true;
		return 1+movingCountCore(threshold,rows,cols,row,col+1,isVisited)
		+movingCountCore(threshold,rows,cols,row,col-1,isVisited)
		+movingCountCore(threshold,rows,cols,row+1,col,isVisited)
		+movingCountCore(threshold,rows,cols,row-1,col,isVisited);
	}
	private int cal(int num){
		int sum=0;
		while(num>0){
		sum+=num%10;
		num/=10;
		}
	return sum;
	}
}
